package com.ham.mud.commands;

import com.ham.mud.Colors;
import com.ham.mud.ServerConnection;
import com.ham.mud.Targetable;
import com.ham.mud.TargetableService;
import com.ham.mud.characters.mobs.Mob;
import com.ham.mud.characters.player.Player;
import com.ham.mud.rooms.Room;
import com.ham.mud.rooms.RoomService;

/**
 * Created by hlucas on Jun 29, 2011 at 11:23:29 AM
 */
public class ConsiderCommand extends PlayerCommand {
    @Override
    public void execute(ServerConnection connection, String[] params) {
        if(params.length == 0) {
            connection.printSolo(Colors.NEW_LINE + "Consider who?");
            return;
        }

        String target = params[0];
        if(target == null || target.trim().equals("")) {
            connection.printSolo(Colors.NEW_LINE + "Consider who?");
            return;
        }

        Player player = connection.getPlayer();
        int atX = player.getAtX();
        int atY = player.getAtY();
        Room room = RoomService.getRoom(player.getZone(), atX, atY);
        Targetable targetable = TargetableService.findTarget(target, room.getMobs());
        if(targetable == null) {
            connection.printSolo(Colors.NEW_LINE + "Consider who?");
            return;
        }
        int level = ((Mob)targetable).getLevel();
        connection.printSolo(((Mob) targetable).getName() + " is level " + level + ".");
    }

    @Override
    protected String getCommandName() {
        return "consider";
    }
}
